package wedaex.content;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;


@SuppressWarnings("serial")
public class Page implements Serializable {
	private ContentSource source;
	private String content;
	private String encoding;
	public Page(ContentSource source, String content, String encoding) {
		this.source = source;
		this.content = content;
		this.encoding = encoding;
	}
	public String getContent() {
		return content;
	}
	public String getEncoding() {
		return encoding;
	}
	public ContentSource getSource() {
		return source;
	}
	public String getUrl() {
		return source.getUrl();
	}
	public String getContentPreview(int maxLength) {
		if(content.length() <= maxLength) return StringUtils.remove(content, "\n");
		return StringUtils.remove(content, "\n").substring(0, maxLength-3) + "...";
	}
	
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
				.append("source", source)
				.append("content", getContentPreview(50))
				.append("encoding", encoding)
				.toString();
	}
}
